package com.football.springboot.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.football.springboot.common.Result;
import com.football.springboot.common.Return;
import com.football.springboot.entity.*;
import com.football.springboot.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@Api(tags = "echarts管理")
@RestController
@RequestMapping("/echarts")
public class EchartsController {
    @Resource
    private UserService userService;

    @Resource
    private ITeamService teamService;

    @Resource
    private ITeamDataService teamDataService;

    @Resource
    private ITeamDataSingleService teamDataSingleService;

    @Resource
    private ITeamAbilityService teamAbilityService;

    @Resource
    private IPlayerService playerService;

    @Resource
    private IPlayerDataService playerDataService;

    @Resource
    private IPlayerAbilityService playerAbilityService;


    @Resource
    private IGameDataService gameDataService;

    @Resource
    private IGameService gameService;


    @Resource
    private IPlayerDataSingleService playerDataSingleService;

    @Resource
    private ILeagueService leagueService;

    //图 每个角色用户人数分配
    @ApiOperation("饼状图 每个角色用户人数分配")
    @RequestMapping(value = "/rolepie",method = RequestMethod.GET)
    public Return rolepie(){
        List<User> list = userService.list();
        int admincount = 0;//管理员人数
        int superadmincount = 0;//超级管理员人数
        int commoncount = 0;//普通用户人数

        for (User user : list){
            if (user.getRole().equals("ROLE_ADMIN")){
                admincount+=1;
            }else if(user.getRole().equals("ROLE_SUPER_ADMIN")){
                superadmincount+=1;
            }else{
                commoncount+=1;
            }
        }
        Map<String,Object> map = new HashMap<>();
        map.put("count",CollUtil.newArrayList(admincount,superadmincount,commoncount));
        System.out.println(map);
        return Return.ok().put("map",map);
    }

    //图 球队能力图
    @ApiOperation("球队能力图")
    @GetMapping("/front/teamAbility")
    public Result teamAbility(@RequestParam Integer teamId){
        //球队能力
        QueryWrapper<TeamAbility> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(teamId!=null,"team_id",teamId);
        TeamAbility teamAbility=teamAbilityService.getOne(queryWrapper);
       // System.err.println(teamAbility.getCapability()+teamAbility.getAttack()+teamAbility.getDefense());
        Map<String,Object> map = new HashMap<>();
        if (!ObjectUtils.isEmpty(teamAbility)){
            map.put("count",CollUtil.newArrayList(teamAbility.getDefense(),teamAbility.getAttack(),teamAbility.getCapability()));
        }
       // map.put("count",CollUtil.newArrayList(teamAbility.getDefense(),teamAbility.getAttack(),teamAbility.getCapability()));
       // System.err.println("aaaaaaaaaaaaaaaaaaaaaaa"+teamId);
       // System.err.println(map);

        return Result.success(map);
    }


    //图 球员能力六维图
    @ApiOperation("球员能力六维图")
    @GetMapping("/front/playerAbilitysix")
    public Result playerAbilitysix(@RequestParam Integer playerId){
        //球员六维能力
        QueryWrapper<PlayerAbility> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(playerId!=null,"player_id",playerId);
        PlayerAbility playerAbility=playerAbilityService.getOne(queryWrapper);
        Integer speed = playerAbility.getSpeed();
        Integer power = playerAbility.getPower();
        Integer shoot = playerAbility.getShoot();
        Integer pass = playerAbility.getPass();
        Integer dribble = playerAbility.getDribble();
        Integer technique = playerAbility.getTechnique();
        Map<String,Object> map = new HashMap<>();
        if (!ObjectUtils.isEmpty(playerAbility)){
            map.put("count",CollUtil.newArrayList(speed,power,shoot,pass,dribble,technique));
        }

        return  Result.success(map);
    }
    //图 球员能力图
    @ApiOperation("球员能力图")
    @GetMapping("/front/playerAbility")
    public Result playerAbility(@RequestParam Integer playerId){
        //球员能力
        QueryWrapper<PlayerAbility> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(playerId!=null,"player_id",playerId);
        PlayerAbility playerAbility=playerAbilityService.getOne(queryWrapper);
        Integer capability = playerAbility.getCapability();
        Integer attack = playerAbility.getAttack();
        Integer defense = playerAbility.getDefense();
        Integer freekick = playerAbility.getFreekick();
        Integer stamina = playerAbility.getStamina();
        Integer header = playerAbility.getHeader();
        Integer jump  = playerAbility.getJump();
        Integer keeper = playerAbility.getKeeper();
        Integer teamwork = playerAbility.getTeamwork();
        Map<String,Object> map = new HashMap<>();
        if (!ObjectUtils.isEmpty(playerAbility)){
            map.put("count",CollUtil.newArrayList(teamwork,keeper,jump,header,stamina,freekick,defense,attack,capability));
        }
        //capability,attack,defense,freekick,stamina,header,jump,keeper,teamwork
        //teamwork,keeper,jump,header,stamina,freekick,defense,attack,capability
        return Result.success(map);
    }

    //单场比赛技术统计双向柱状图
    @ApiOperation("单场比赛技术统计双向柱状图")
    @GetMapping("/front/gamestatistics")
    public Return gamestatistics(@RequestParam Integer gameId){
        QueryWrapper<GameData> queryWrappergd=new QueryWrapper<>();
        QueryWrapper<Team> queryWrappert=new QueryWrapper<>();
        queryWrappergd.eq(gameId!=null,"game_id",gameId);
        GameData gameData=gameDataService.getOne(queryWrappergd);
        Team hometeaminfo=teamService.getById(gameService.getById(gameId).getHomeTeam());
        Team awayteaminfo=teamService.getById(gameService.getById(gameId).getAwayTeam());
        gameData.setHomeTeamInfo(hometeaminfo);
        gameData.setAwayTeamInfo(awayteaminfo);

        Map<String,Object> homemap = new HashMap<>();
        Map<String,Object> awaymap = new HashMap<>();
        Map<String,Object> homeattackmap = new HashMap<>();
        Map<String,Object> awayattackmap = new HashMap<>();
        Map<String,Object> homepassmap = new HashMap<>();
        Map<String,Object> awaypassmap = new HashMap<>();
        homemap=gameDataService.getgamehomedatamap(homemap,gameData);
        homeattackmap=gameDataService.getgamehomeattackdatamap(homeattackmap,gameData);
        homepassmap=gameDataService.getgamehomepassdatamap(homepassmap,gameData);
        awaymap=gameDataService.getgameawaydatamap(awaymap,gameData);
        awayattackmap=gameDataService.getgameawayattackdatamap(awayattackmap,gameData);
        awaypassmap=gameDataService.getgameawaypassdatamap(awaypassmap,gameData);


        return Return.ok().put("homemap",homemap).put("awaymap",awaymap)
                .put("homeattackmap",homeattackmap)
                .put("homepassmap",homepassmap)
                .put("awaymap",awaymap)
                .put("awayattackmap",awayattackmap)
                .put("awaypassmap",awaypassmap)
                .put("gameData",gameData);
    }



    //球队赛季总数据分析比较图 统计双向柱状图
    @ApiOperation("球队赛季总数据分析比较图")
    @GetMapping("/front/compareteam")
    public Return compareteam(@RequestParam Integer leagueId
                             ,@RequestParam Integer teamId,@RequestParam String homeAway){
        TeamData teamData = new TeamData();
        teamData.setTeam(teamService.getById(teamId));
        Map<String,Object> teamdatamap = new HashMap<>();
        Map<String,Object> teamattackdatamap = new HashMap<>();
        Map<String,Object> teampassdatamap = new HashMap<>();
        Map<String,Object> teamavedatamap = new HashMap<>();
        Map<String,Object> teamaveattackdatamap = new HashMap<>();
        Map<String,Object> teamavepassdatamap = new HashMap<>();
        System.err.println("初始化："+teamData);
        if (homeAway.equals("主场")){
            if (leagueId!=null){//查询一支球队一个联赛主场数据
                System.err.println("查询主场单联赛：");
                QueryWrapper<TeamData> queryWrappertd = new QueryWrapper<>();
                queryWrappertd.eq(teamId!=null,"team_id",teamId);
                queryWrappertd.eq("league_id",leagueId);
                queryWrappertd.like("home_away","主场");
                teamData=teamDataService.getOne(queryWrappertd);
                teamData.setTeam(teamService.getById(teamId));
                System.err.println(teamId+" "+leagueId+" "+"单联赛主场数据："+teamData);
                //找的到再返回
                if (!ObjectUtils.isEmpty(teamData)){
                    teamData.setTeam(teamService.getById(teamId));
                    teamDataService.countleague(teamData);
                    return Return.ok().put("teamdatamap",teamDataService.getteamdatamap(teamdatamap,teamData))
                            .put("teamattackdatamap",teamDataService.getteamattackdatamap(teamattackdatamap,teamData))
                            .put("teampassdatamap",teamDataService.getteampassdatamap(teampassdatamap,teamData))
                            .put("teamavedatamap",teamDataService.getteamavedatamap(teamavedatamap,teamData))
                            .put("teamaveattackdatamap",teamDataService.getteamaveattackdatamap(teamaveattackdatamap,teamData))
                            .put("teamavepassdatamap",teamDataService.getteamavepassdatamap(teamavepassdatamap,teamData))
                            .put("teamData",teamData);
                }else{
                    return Return.ok().put("teamdatamap",teamDataService.getteamdatamap(teamdatamap,teamData))
                            .put("teamattackdatamap",teamDataService.getteamattackdatamap(teamattackdatamap,teamData))
                            .put("teampassdatamap",teamDataService.getteampassdatamap(teampassdatamap,teamData))
                            .put("teamavedatamap",teamDataService.getteamavedatamap(teamavedatamap,teamData))
                            .put("teamaveattackdatamap",teamDataService.getteamaveattackdatamap(teamaveattackdatamap,teamData))
                            .put("teamavepassdatamap",teamDataService.getteamavepassdatamap(teamavepassdatamap,teamData))
                            .put("teamData",teamData);
                }
            }else{//查询一支球队所有联赛的总主场数据
                //先查出一支球队参加了哪些联赛 也可以使用querywrapper
                System.err.println("查询主场所有联赛");
                QueryWrapper<TeamData> queryWrappertds = new QueryWrapper<>();
                queryWrappertds.eq("team_id",teamId);
                queryWrappertds.eq("home_away","主场");

                List<TeamData> hometeamDataList=teamDataService.list(queryWrappertds);
                TeamData hometeamDataall=new TeamData();
                hometeamDataall=teamDataService.teamDataallleague(hometeamDataList,hometeamDataall);
                hometeamDataall.setTeam(teamService.getById(teamId));
                teamDataService.countleague(hometeamDataall);
                System.err.println(hometeamDataall);
                return Return.ok().put("teamdatamap",teamDataService.getteamdatamap(teamdatamap,hometeamDataall))
                        .put("teamattackdatamap",teamDataService.getteamattackdatamap(teamattackdatamap,hometeamDataall))
                        .put("teampassdatamap",teamDataService.getteampassdatamap(teampassdatamap,hometeamDataall))
                        .put("teamavedatamap",teamDataService.getteamavedatamap(teamavedatamap,hometeamDataall))
                        .put("teamaveattackdatamap",teamDataService.getteamaveattackdatamap(teamaveattackdatamap,hometeamDataall))
                        .put("teamavepassdatamap",teamDataService.getteamavepassdatamap(teamavepassdatamap,hometeamDataall))
                        .put("teamData",hometeamDataall);
            }
        }
        if(homeAway.equals("客场")){
            if (leagueId!=null){//查询一支球队一个联赛客场数据
                System.err.println("查询客场单联赛：");
                QueryWrapper<TeamData> queryWrappertd = new QueryWrapper<>();
                queryWrappertd.eq(teamId!=null,"team_id",teamId);
                queryWrappertd.eq("league_id",leagueId);
                queryWrappertd.like("home_away","客场");
                teamData=teamDataService.getOne(queryWrappertd);
                teamData.setTeam(teamService.getById(teamId));
                //找得到再返回
                if (!ObjectUtils.isEmpty(teamData)){
                    teamDataService.countleague(teamData);
                    return Return.ok().put("teamdatamap",teamDataService.getteamdatamap(teamdatamap,teamData))
                            .put("teamattackdatamap",teamDataService.getteamattackdatamap(teamattackdatamap,teamData))
                            .put("teampassdatamap",teamDataService.getteampassdatamap(teampassdatamap,teamData))
                            .put("teamavedatamap",teamDataService.getteamavedatamap(teamavedatamap,teamData))
                            .put("teamaveattackdatamap",teamDataService.getteamaveattackdatamap(teamaveattackdatamap,teamData))
                            .put("teamavepassdatamap",teamDataService.getteamavepassdatamap(teamavepassdatamap,teamData))
                            .put("teamData",teamData);
                }else{
                    return Return.ok().put("teamdatamap",teamDataService.getteamdatamap(teamdatamap,teamData))
                            .put("teamattackdatamap",teamDataService.getteamattackdatamap(teamattackdatamap,teamData))
                            .put("teampassdatamap",teamDataService.getteampassdatamap(teampassdatamap,teamData))
                            .put("teamavedatamap",teamDataService.getteamavedatamap(teamavedatamap,teamData))
                            .put("teamaveattackdatamap",teamDataService.getteamaveattackdatamap(teamaveattackdatamap,teamData))
                            .put("teamavepassdatamap",teamDataService.getteamavepassdatamap(teamavepassdatamap,teamData))
                            .put("teamData",teamData);
                }
            }else{//查询一支球队所有联赛的总客场数据
                System.err.println("查询客场所有联赛");
                QueryWrapper<TeamData> queryWrappertds = new QueryWrapper<>();
                queryWrappertds.eq("team_id",teamId);
                queryWrappertds.eq("home_away","客场");
                List<TeamData> awayteamDataList=teamDataService.list(queryWrappertds);
                TeamData awayteamDataall=new TeamData();
                awayteamDataall=teamDataService.teamDataallleague(awayteamDataList,awayteamDataall);
                awayteamDataall.setTeam(teamService.getById(teamId));
                teamDataService.countleague(awayteamDataall);
                System.err.println(awayteamDataall);
                return Return.ok().put("teamdatamap",teamDataService.getteamdatamap(teamdatamap,awayteamDataall))
                        .put("teamattackdatamap",teamDataService.getteamattackdatamap(teamattackdatamap,awayteamDataall))
                        .put("teampassdatamap",teamDataService.getteampassdatamap(teampassdatamap,awayteamDataall))
                        .put("teamavedatamap",teamDataService.getteamavedatamap(teamavedatamap,awayteamDataall))
                        .put("teamaveattackdatamap",teamDataService.getteamaveattackdatamap(teamaveattackdatamap,awayteamDataall))
                        .put("teamavepassdatamap",teamDataService.getteamavepassdatamap(teamavepassdatamap,awayteamDataall))
                        .put("teamData",awayteamDataall);
            }

        }
        if (homeAway.equals("全部") || homeAway.equals("")){
            if (leagueId!=null){//查询一支球队一个联赛的总数据
                TeamData hometeamdata=teamDataService.getupdategamedata(teamId,leagueId,"主场");
                TeamData awayteamdata = teamDataService.getupdategamedata(teamId,leagueId,"客场");
                //判断主客场数据存在的情况
                if (!ObjectUtils.isEmpty(awayteamdata) && !ObjectUtils.isEmpty(hometeamdata)) {//主客场都存在
                    //主客场数据执行相加
                    teamData = teamDataService.teamDataall(hometeamdata,awayteamdata);
                    teamData.setTeam(teamService.getById(teamId));
                    teamDataService.countleague(teamData);
                    return Return.ok().put("teamdatamap",teamDataService.getteamdatamap(teamdatamap,teamData))
                            .put("teamattackdatamap",teamDataService.getteamattackdatamap(teamattackdatamap,teamData))
                            .put("teampassdatamap",teamDataService.getteampassdatamap(teampassdatamap,teamData))
                            .put("teamavedatamap",teamDataService.getteamavedatamap(teamavedatamap,teamData))
                            .put("teamaveattackdatamap",teamDataService.getteamaveattackdatamap(teamaveattackdatamap,teamData))
                            .put("teamavepassdatamap",teamDataService.getteamavepassdatamap(teamavepassdatamap,teamData))
                            .put("teamData",teamData);
                }else if (!ObjectUtils.isEmpty(hometeamdata) && ObjectUtils.isEmpty(awayteamdata)){//只有主场数据
                    hometeamdata.setTeam(teamService.getById(teamId));
                    teamDataService.countleague(hometeamdata);
                    return Return.ok().put("teamdatamap",teamDataService.getteamdatamap(teamdatamap,hometeamdata))
                            .put("teamattackdatamap",teamDataService.getteamattackdatamap(teamattackdatamap,hometeamdata))
                            .put("teampassdatamap",teamDataService.getteampassdatamap(teampassdatamap,hometeamdata))
                            .put("teamavedatamap",teamDataService.getteamavedatamap(teamavedatamap,hometeamdata))
                            .put("teamaveattackdatamap",teamDataService.getteamaveattackdatamap(teamaveattackdatamap,hometeamdata))
                            .put("teamavepassdatamap",teamDataService.getteamavepassdatamap(teamavepassdatamap,hometeamdata))
                            .put("teamData",hometeamdata);
                }else if (!ObjectUtils.isEmpty(awayteamdata) && ObjectUtils.isEmpty(hometeamdata)){//只有客场数据
                    awayteamdata.setTeam(teamService.getById(teamId));
                    teamDataService.countleague(awayteamdata);
                    return Return.ok().put("teamdatamap",teamDataService.getteamdatamap(teamdatamap,awayteamdata))
                            .put("teamattackdatamap",teamDataService.getteamattackdatamap(teamattackdatamap,awayteamdata))
                            .put("teampassdatamap",teamDataService.getteampassdatamap(teampassdatamap,awayteamdata))
                            .put("teamavedatamap",teamDataService.getteamavedatamap(teamavedatamap,awayteamdata))
                            .put("teamaveattackdatamap",teamDataService.getteamaveattackdatamap(teamaveattackdatamap,awayteamdata))
                            .put("teamavepassdatamap",teamDataService.getteamavepassdatamap(teamavepassdatamap,awayteamdata))
                            .put("teamData",awayteamdata);
                }
            }else{//查询一支球队所有联赛的总数据
                System.err.println("查询所有联赛数据");
                QueryWrapper<TeamData> queryWrappertds = new QueryWrapper<>();
                queryWrappertds.eq("team_id",teamId);
                List<TeamData> teamDataList=teamDataService.list(queryWrappertds);
                TeamData teamDataall=new TeamData();
                teamDataall.setTeam(teamService.getById(teamId));
                teamDataall=teamDataService.teamDataallleague(teamDataList,teamDataall);
                teamDataService.countleague(teamDataall);
                System.err.println(teamDataall);
                return Return.ok().put("teamdatamap",teamDataService.getteamdatamap(teamdatamap,teamDataall))
                        .put("teamattackdatamap",teamDataService.getteamattackdatamap(teamattackdatamap,teamDataall))
                        .put("teampassdatamap",teamDataService.getteampassdatamap(teampassdatamap,teamDataall))
                        .put("teamavedatamap",teamDataService.getteamavedatamap(teamavedatamap,teamDataall))
                        .put("teamaveattackdatamap",teamDataService.getteamaveattackdatamap(teamaveattackdatamap,teamDataall))
                        .put("teamavepassdatamap",teamDataService.getteamavepassdatamap(teamavepassdatamap,teamDataall))
                        .put("teamData",teamDataall);
            }
        }

        return Return.ok().put("teamdatamap",teamDataService.getteamdatamap(teamdatamap,teamData))
                .put("teamattackdatamap",teamDataService.getteamattackdatamap(teamattackdatamap,teamData))
                .put("teampassdatamap",teamDataService.getteampassdatamap(teampassdatamap,teamData))
                .put("teamavedatamap",teamDataService.getteamavedatamap(teamavedatamap,teamData))
                .put("teamaveattackdatamap",teamDataService.getteamaveattackdatamap(teamaveattackdatamap,teamData))
                .put("teamavepassdatamap",teamDataService.getteamavepassdatamap(teamavepassdatamap,teamData))
                .put("teamData",teamData);
    }

    //球员赛季总数据分析比较图 统计双向柱状图
    @ApiOperation("球员赛季总数据分析比较图")
    @GetMapping("/front/compareplayer")
    public Return compareplayer(@RequestParam Integer playerId
                               ,@RequestParam Integer leagueId){
        //球员赛季数据
        PlayerData playerData = new PlayerData();
        System.err.println("初始化：" + playerData);
        Map<String,Object> playerdatamap = new HashMap<>();
        Map<String,Object> playerattackdatamap = new HashMap<>();
        Map<String,Object> playerpassdatamap = new HashMap<>();
        Map<String,Object> playeravedatamap = new HashMap<>();
        Map<String,Object> playeraveattackdatamap = new HashMap<>();
        Map<String,Object> playeravepassdatamap = new HashMap<>();
        QueryWrapper<PlayerData> queryWrapperpd = new QueryWrapper<>();

        if (leagueId != null) {//查出单个联赛球员数据
            System.err.println("查出单个联赛球员数据");
            queryWrapperpd.eq("league_id", leagueId);
            queryWrapperpd.eq("player_id", playerId);
            playerData = playerDataService.getOne(queryWrapperpd);
            playerData.setPlayer(playerService.getById(playerId));
            playerDataService.countplayerleague(playerData);
            return Return.ok().put("playerdatamap",playerDataService.getplayerdatamap(playerdatamap,playerData))
                    .put("playerattackdatamap",playerDataService.getplayerattackdatamap(playerattackdatamap,playerData))
                    .put("playerpassdatamap",playerDataService.getplayerpassdatamap(playerpassdatamap,playerData))
                    .put("playeravedatamap",playerDataService.getplayeravedatamap(playeravedatamap,playerData))
                    .put("playeraveattackdatamap",playerDataService.getplayeraveattackdatamap(playeraveattackdatamap,playerData))
                    .put("playeravepassdatamap",playerDataService.getplayeravepassdatamap(playeravepassdatamap,playerData))
                    .put("playerData",playerData);
        } else {//查出所有联赛的球员数据和
            System.err.println("查出所有联赛的球员数据和");
            QueryWrapper<PlayerData> queryWrapperpds = new QueryWrapper<>();
            queryWrapperpds.eq("player_id", playerId);
            List<PlayerData> playerDataList = playerDataService.list(queryWrapperpds);
            PlayerData playerDataall = new PlayerData();
            playerDataall = playerDataService.playerDataallleague(playerDataList, playerDataall);
            playerDataall.setPlayer(playerService.getById(playerId));
            playerDataService.countplayerleague(playerDataall);
            return Return.ok().put("playerdatamap",playerDataService.getplayerdatamap(playerdatamap,playerDataall))
                    .put("playerattackdatamap",playerDataService.getplayerattackdatamap(playerattackdatamap,playerDataall))
                    .put("playerpassdatamap",playerDataService.getplayerpassdatamap(playerpassdatamap,playerDataall))
                    .put("playeravedatamap",playerDataService.getplayeravedatamap(playeravedatamap,playerDataall))
                    .put("playeraveattackdatamap",playerDataService.getplayeraveattackdatamap(playeraveattackdatamap,playerDataall))
                    .put("playeravepassdatamap",playerDataService.getplayeravepassdatamap(playeravepassdatamap,playerDataall))
                    .put("playerData",playerDataall);
        }
    }


    //球员单场数据柱状图（返回map）
    @ApiOperation("球员单场数据柱状图")
    @GetMapping("/front/playerdatasingle")
    public Return playerdatasingle(@RequestParam Integer gameId,
                                   @RequestParam Integer playerId){

        PlayerDataSingle playerDataSingle = playerDataSingleService.getPlayerDataSingle(playerId,gameId);
        Map<String,Object> pdsmap = new HashMap<>();


        return Return.ok().put("pdsmap",playerDataService.getpdsmap(pdsmap,playerDataSingle));
    }

    //球员单场进攻数据柱状图（返回进攻map）
    @ApiOperation("球员单场进攻数据柱状图")
    @GetMapping("/front/getattacksingledata")
    public Return getattacksingledata(@RequestParam Integer gameId,
                                   @RequestParam Integer playerId){

        PlayerDataSingle playerDataSingle = playerDataSingleService.getPlayerDataSingle(playerId,gameId);
        Map<String,Object> pdsmap = new HashMap<>();


        return Return.ok().put("pdsmap",playerDataService.getattackpdsmap(pdsmap,playerDataSingle));
    }

    //球员单场传球数据柱状图（返回传球map）
    @ApiOperation("球员单场传球数据柱状图")
    @GetMapping("/front/getpasssingledata")
    public Return getpasssingledata(@RequestParam Integer gameId,
                                      @RequestParam Integer playerId){

        PlayerDataSingle playerDataSingle = playerDataSingleService.getPlayerDataSingle(playerId,gameId);
        Map<String,Object> pdsmap = new HashMap<>();


        return Return.ok().put("pdsmap",playerDataService.getpasspdsmap(pdsmap,playerDataSingle));
    }
    //球员单场防守与犯规数据柱状图（返回防守与犯规map）
    @ApiOperation("球员单场防守与犯规数据柱状图")
    @GetMapping("/front/getfoulsingledata")
    public Return getfoulsingledata(@RequestParam Integer gameId,
                                    @RequestParam Integer playerId){

        PlayerDataSingle playerDataSingle = playerDataSingleService.getPlayerDataSingle(playerId,gameId);
        Map<String,Object> pdsmap = new HashMap<>();

        return Return.ok().put("pdsmap",playerDataService.getfoulpdsmap(pdsmap,playerDataSingle));
    }


    //单支球队赛程比赛数据折线变化图(根据比赛时间或联赛轮次)
    @ApiOperation("球队赛程比赛数据折线变化图")
    @GetMapping("/front/getteamgamechange")
    public Result getteamgamechange(@RequestParam Integer teamId,
                                    @RequestParam Integer leagueId){

        //根据team_data_single表 一个球队根据比赛时间或者一个联赛的比赛轮次作为x轴,各种数据作为y轴 折线图数据

        QueryWrapper<Game> queryWrapperg=new QueryWrapper<>();
        queryWrapperg.eq(leagueId!=null,"league_id",leagueId);
        List<Game> gameList=gameService.list(queryWrapperg);
        gameList.sort(Comparator.comparing(Game::getGameTime).reversed());
        List<Integer> gameids = gameList.stream().map(Game::getId).collect(Collectors.toList());

        List<TeamDataSingle> tdslist=new ArrayList<>();
        QueryWrapper<TeamDataSingle> queryWrappertds = new QueryWrapper<>();
        queryWrappertds.eq(teamId!=null,"team_id",teamId);
        queryWrappertds.in("game_id",gameids);
        tdslist=teamDataSingleService.list(queryWrappertds);
        tdslist.forEach(teamDataSingle -> {
            teamDataSingle.setGame(gameService.getById(teamDataSingle.getGameId()));
            teamDataSingle.setLeague(leagueService.getById(teamDataSingle.getGame().getLeagueId()));
        });
        tdslist.sort(Comparator.comparing(teamDataSingle -> teamDataSingle.getGame().getGameTime()));

        //下面数据在前端转为map
        //球队进球数据
        //球队失球数据
        //球队控球
        //球队射门（射正）
        //球队传球（成功传球）
        //球队过人
        //球队越位
        //球队犯规
        //球队黄牌
        //球队红牌

        return Result.success(tdslist);
    }



    //单名球员赛程数据折线变化图
    @ApiOperation("球员赛程数据折线变化图")
    @GetMapping("/front/getplayergamechange")
    public Result getplayergamechange(@RequestParam Integer playerId,
                                      @RequestParam Integer leagueId){
        //根据player_data_single表 一个球员根据比赛时间或者一个联赛的比赛轮次作为x轴,各种数据作为y轴 折线图数据
        QueryWrapper<Game> queryWrapperg=new QueryWrapper<>();
        queryWrapperg.eq(leagueId!=null,"league_id",leagueId);
        List<Game> gameList=gameService.list(queryWrapperg);
        gameList.sort(Comparator.comparing(Game::getGameTime).reversed());
        List<Integer> gameids = gameList.stream().map(Game::getId).collect(Collectors.toList());

        List<PlayerDataSingle> pdslist=new ArrayList<>();
        QueryWrapper<PlayerDataSingle> queryWrapperpds = new QueryWrapper<>();
        queryWrapperpds.eq(playerId!=null,"player_id",playerId);
        queryWrapperpds.in("game_id",gameids);
        pdslist=playerDataSingleService.list(queryWrapperpds);
        pdslist.forEach(playerDataSingle -> {
            playerDataSingle.setGame(gameService.getById(playerDataSingle.getGameId()));
            playerDataSingle.setLeague(leagueService.getById(playerDataSingle.getGame().getLeagueId()));
        });
        pdslist.sort(Comparator.comparing(playerDataSingle -> playerDataSingle.getGame().getGameTime()));
        //下面数据在前端转为map
        //球员进球数
        //球员助攻数
        //球员射门数
        //球员射正数
        //球员传球（成功传球）
        //球员过人（成功过人）
        //球员抢断
        //球员越位
        //球员犯规
        //球员被犯规
        //球员黄牌
        //球员红牌

        return Result.success(pdslist);
    }



}
